package com.example.moneybook.controller;

import com.example.moneybook.dto.ResponseResult;
import com.example.moneybook.pojo.Bill;
import com.example.moneybook.service.DetailService;
import lombok.AllArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * @Author: 包
 * @Date: 2023/1/15 18:39
 * Description:
 */

@RestController
@RequestMapping("/detail")
public class DetailController {

    @Autowired
    private DetailService detailService;

    @PostMapping("/load")
    public ResponseResult load(@RequestParam("userId") String userId, @RequestParam("billDate") String billDate) throws ParseException {
        return detailService.load(userId, billDate);
    }

    @PostMapping("/adddetail")
    public ResponseResult addDetail(@RequestBody Bill bill, @RequestParam("accountName") String accountName){
        return detailService.addDetail(bill, accountName);
    }

    @PostMapping("/updatedetail")
    public ResponseResult updateDetail(@RequestBody Bill bill, @RequestParam("accountName") String accountName){
        return detailService.updateBill(bill, accountName);
    }

    @PostMapping("deletebill")
    public ResponseResult deletebill(String userId, int billId){
        return detailService.deleteBill(userId, billId);
    }
}
